<?php
	class OviStoreAction extends  BaseAction{
		public function index(){
				$quyu = M("area")->select();
				$this->assign("area",$quyu);
				$type = M("type")->select();
				$this->assign("type",$type);
				$rent = M("rent")->select();
				$this->assign("rent",$rent);
				if(!$this->isPost()){
					import("ORG.Util.Page");
					$count = M("shangpu")->count();
					$page  = new Page($count,15);
					$show = $page->show();
					$result = M("shangpu")->limit($page->firstRow.','.$page->listRows)->select();
					$start = $page->firstRow+1;
					$end = $page->listRows;
					if($count<$end){
						$end = $count;
					}
					$this->assign("shangpu",$result);
					$this->assign("page",$show);
					$this->assign("count",$count);		
					$this->assign("start",$start);
					$this->assign("end",$end);
					$this->display();
				}else{
				$sql= '';
				if($_POST['areas']!=''){
					if($sql==''){
						$sql.="s_quyu='$_POST[areas]'";
					}else{
						$sql.=" and s_quyu='$_POST[areas]'";
					}
				}
				if($_POST['zongjias']!=''){
				$zongjia = $_POST['zongjias'];
				$money = explode("-",$zongjia);
				if($sql==''){
					$sql.="s_zongjia>=$money[0] and s_zongjia<=$money[1]";
				}else{
					$sql.=" and s_zongjia>=$money[0] and s_zongjia<=$money[1]";
				}
			}
			if($_POST['subways']!=''){
				if($sql==''){
					$sql.="s_subway='$_POST[subways]'";
				}else{
					$sql.=" and s_subway='$_POST[subways]'";
				}
			}
			if($_POST['types']!=''){
				if($sql==''){
					$sql.="s_type='$_POST[types]'";
				}else{
					$sql.=" and s_type='$_POST[types]'";
				}
			}
			if($_POST['rents']!=''){
				if($sql==''){
					$sql.="s_rent='$_POST[rents]'";
				}else{
					$sql.=" and s_rent='$_POST[rents]'";
				}
			}
			
			$this->assign("areas",$_POST['areas']);
			$this->assign("zongjias",$_POST['zongjias']);
			$this->assign("subways",$_POST['subways']);
			$this->assign("types",$_POST['types']);
			$this->assign("rents",$_POST['rents']);
			import("ORG.Util.Page");
			$count = M("shangpu")->where($sql)->count();
			$page  = new Page($count,15);
			$show = $page->show();
			$result = M("shangpu")->where($sql)->limit($page->firstRow.','.$page->listRows)->select();
			$this->assign("shangpu",$result);	
			$start = $page->firstRow+1;
			$end = $start+14;
					if($count<$end){
						$end = $count;
					}
			$this->assign("shangpu",$result);
			$this->assign("page",$show);
			$this->assign("count",$count);			
			$this->assign("start",$start);
			$this->assign("end",$end);
			$this->assign("page",$show);
			$this->display("lists");
		}

	}
	}


?>